<?php
namespace View;

class CommentView 
{
	
	const NOT_EMPTY = 0;
	const COMMENT_PASSED = 1;
	const COMMENT_FAILED = 2;
	const COMMENT_DELETED = 3;
	const COMMENT_NOT_DELETED = 4;
	private $name = "name";
	private $comment = "comment";
	private $submit = "submit";
	private $deleteComment = "deleteComment";
	private $commentBotton = "commentBotton";
	private $commentId = "";
	private $commentsId = "commentid";

	//Skapar html för att visa alla komentarer beronde på post
	public function ShowListOfComments(\Model\CommentArray $commentArray)
	{
		$db = "";
		$lH = new \Model\loginHandler($db);
		$ret = "";
		foreach ($commentArray->get() as $comment) {
			$ret .= "<div class='post'>";
			$ret .= "<h2>". $comment -> getName()."</h2>";
			$ret .= "<p class='meta'>Posted on " . $comment->getdate() . " &nbsp;&bull;&nbsp</p>"; 
			$ret .= "<div class='entry'><p>" . $comment->getComment() ."</p> </div>";
			
		    
			if($lH->IsLoggedIn())
			{
				$ret .= $this->DeletedComment($comment);
			}
			$ret .= "</div>";
		}

		return $ret;
	}
	//Skapar html för att skapa en ny kommentar
	public function DoNewComment()
	{
		$html = "<div>
				<h3>Leave a comment</h3>
					<form method ='post' action=''/>
						<h4>Name</h4>
								<input type='text' name='$this->name'/></br>
						Comment:</br>
								<textarea type='text' rows='5' cols='20' name='$this->comment'></textarea></br>
						<input type='submit' value='Submit' class='css3button' name='$this->submit'/>
					</form>
			</div>";
		return $html;
	}
	//Skapar html för att ta bort kommentar
	function DeletedComment(\Model\Comment $comment)
	{
		$this->commentId = $comment->getCommentId();
		return "<div> 
					<form method='post' action=''></br>
						<input type='hidden' name='$this->commentsId' value='$this->commentId'/>
						<input type='submit' value='Delete' name='$this->deleteComment'/>  
					</form>
				</div>";
	}
	// Dessa funktoner knyter samman det som man skrivit eller tryckt på så att de kan få värden 
	public function PostName()
	{
		if (isset($_POST[$this -> name]) == true) {
			return $_POST[$this -> name];
		}
		return null;
	}
	public function PostComment()
	{
		if (isset($_POST[$this -> comment]) == true) {
			return $_POST[$this -> comment];
		}
		return null;
	}
	public function TriedToSubmitComment()
	{
		if (isset($_POST[$this -> submit]) == true) {
			return true;
		}
		return false;
	}
	public function Tried2DeleteComment()
	{
		if (isset($_POST[$this->deleteComment]) == true) {
			return true;
		}
		return FALSE;
	}
	public function PostCommentID()
	{
		if (isset($_POST[$this->commentsId]) == true) {
			return $_POST[$this->commentsId];
		}
		return null;
	}
	public function Message($status)
	{
		switch ($status)
		{
			case self::NOT_EMPTY :
				return "<p>You need to write somthing</p>";
				break;
			case self::COMMENT_PASSED :
				return "<p>Youre comment did post</p>";
				break;
			case self::COMMENT_FAILED :
				return "<p>Youre comment didn´t post </p>";
				break;
			case self::COMMENT_DELETED :
				return "<p>Youre Delete was a sucsess</p>";
				break;
			case self::COMMENT_NOT_DELETED :
				return "<p>Youre Delete was a failure</p>";
				break;
			default;
			break;
		}
	}
	

}